package org.jackysoft.service.impl;

import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;

import org.jackysoft.data.AbstractDataProvider;
import org.jackysoft.entity.Role;
import org.jackysoft.mapper.RoleMapper;
import org.jackysoft.query.CompareRelation;
import org.jackysoft.query.RunnerQuery;
import org.jackysoft.service.RoleService;
import org.jackysoft.ztree.RoleZtreeFunction;
import org.jackysoft.ztree.ZTreeNode;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.google.common.collect.Collections2;

@Service
public class RoleServiceImpl extends AbstractDataProvider<Role>
		implements RoleService {

	@Resource 
	RoleMapper mapper;
	
	public RoleServiceImpl() {
		super();
	}

	
	@Override
	public Collection<Role> fromWorkflowSetting(String value) {

		RunnerQuery query = new RunnerQuery();
        query.addField("id", CompareRelation.类似于, value);
        List<Role> list = mapper.query(query);
		
		return list;
	}


	@Override
	public Collection<ZTreeNode> ztree(String parentId) throws DataAccessException {
		Collection<Role> beans = mapper.findAll();
		Collection<ZTreeNode> nodes = Collections2.transform(beans, new RoleZtreeFunction());
		return nodes;
	}

	
}
